require(['./config'], () => {
	require(['swiper', 'template', 'footer','Header', 'bootstrap'], (Swiper, template) => {
		class Index {
			constructor() {

				this.title().then(() => {
					this.init()
				})
				
				this.banner().then(() => {
					this.swiperbanner()
				})
				
				this.moretabby().then(()=>{})
				
				this.handbag().then(()=>{})
				
				this.hotshop().then(()=>{})
				
				this.coachstory().then(()=>{})
				
				this.homelove().then(()=>{})
				
				this.coachserve().then(()=>{})
			}
			init() {

			}

			title() {
				// console.log('ff')
				return new Promise((resolve) => {
					$.get('rest/default/V1/cms/block/identifier/home_banner', (resp) => {
						const {
							link,
							subTitle,
							tipsT,
							title,
						} = resp.data.content
						this.content = {
							link,
							subTitle,
							tipsT,
							title,
						}
						$('#titles').html(
							template('titlesTemplate', { ...this.content
							})
						)
						resolve()
					})
				})
			}

			banner() {
				return new Promise((resolve) => {
					$.get('rest/default/V1/cms/block/identifier/home_banner', (resp) => {
						if (resp.status) {
							this.content2 = resp.data.content
							// console.log(this.content2)
							$('#bannerbox').html(template('bannerboxTemplate', { ...this.content2
							}))
							resolve()
						}
					})
				})
			}
			swiperbanner() {
				var mySwiper = new Swiper('.banner', {
					loop: true, // 循环模式选项
					speed: 2000,
					autoplay: {
						disableOnInteraction: false
					},
					effect: 'coverflow',
					// 如果需要分页器
					pagination: {
						el: '.banner .swiper-pagination',
					},
					// 如果需要前进后退按钮
					navigation: {
						nextEl: '.banner .swiper-button-next',
						prevEl: '.banner .swiper-button-prev',
					},
					// 如果需要滚动条
					scrollbar: {
						el: '.swiper-scrollbar',
					}
				})
			}
			
			moretabby(){
				return new Promise((resolve)=>{
					$.get('/rest/default/V1/cms/block/identifier/home_productItemsList',(resp)=>{
						if(resp.status){
							this.morecontent = resp.data.content
							// console.log(this.morecontent)
							$('#more-tabby').html(template('more-tabbyTemplate',{...this.morecontent}))
							resolve()
						}
					})
				})
			}
			
			handbag(){
				return new Promise((resolve)=>{
					$.get('/rest/default/V1/cms/block/identifier/home_imgZiParallel',(resp)=>{
						if(resp.status){
							this.handbadcontent=resp.data.content.content[0]
							// console.log(this.handbadcontent)
							$('#handbag').html(template('handbagTemplate',{...this.handbadcontent}))
							resolve()
						}
					})
				})
			}
			
			hotshop(){
				return new Promise((resolve)=>{
					$.get('/rest/default/V1/cms/block/identifier/home_hotsellProdcuts',(resp)=>{
						if(resp.status){
							this.hotshopcontent=resp.data.content
							$('#hot-shop').html(template('hot-shopTemplate',{...this.hotshopcontent}))
							resolve()
						}
					})
				})
			}
			
			coachstory(){
				return new Promise((resolve)=>{
					$.get('/rest/default/V1/cms/block/identifier/home_brandStory',(resp)=>{
						if(resp.status){
							this.storycontent=resp.data.content
							$('#coach-story').html(template('coach-storyTemplate',{...this.storycontent}))
							resolve()
						}
					})
				})
			}
			
			homelove(){
				return new Promise((resolve)=>{
					$.get('/rest/default/V1/cms/block/identifier/home_coachCreate',(resp)=>{
						if(resp.status){
							this.lovecontent=resp.data.content
							// console.log(this.lovecontent)
							$('#home-love').html(template('home-loveTemplate',{...this.lovecontent}))
							resolve()
						}
					})
				})
			}
			
			coachserve(){
				return new Promise((resolve)=>{
					$.get('rest/default/V1/cms/block/identifier/home_servicesList',(resp)=>{
						if(resp.status){
							this.servecontent=resp.data.content
							// console.log(this.lovecontent)
							const txt = resp.data.content.items
							txt.forEach((item)=>{
								item.details= item.details.replace(/\<br \/\>/g,'').trim()
							})
							this.res = txt
							console.log(this.res)
							
							$('#coach-serve').html(template('coach-serveTemplate',{...this.servecontent,...this.res}))
							resolve()
						}
					})
				})
			}
			
		}

		new Index()
	})
})
